def dfs_iterative(graph, start):
    visited = set()
    stack = [start]
    result = []
    while stack:
        vertex = stack.pop()
        if vertex not in visited:
            visited.add(vertex)
            result.append(vertex)
            for neighbor in graph[vertex]:
                if neighbor not in visited:
                    stack.append(neighbor)
    return result


if __name__ == "__main__":
    # 示例图（使用邻接表表示）
    _graph = {
        'A': ['B', 'C'],
        'B': ['A', 'D', 'E'],
        'C': ['A', 'F'],
        'D': ['B'],
        'E': ['B', 'F'],
        'F': ['C', 'E']
    }

    print(dfs_iterative(_graph, 'A'))
    # 输出: ['A', 'C', 'F', 'E', 'B', 'D']（顺序可能不同，因为栈是后进先出）
